package domain

import (
	"context"
	"time"
)

type OrderStatus int8

const (
	_ OrderStatus = iota
	ONGOING
	COMPLETE
	SHUTDOWN
)

type Order struct {
	Id         int64
	UserId     int64
	MerchantId int64
	Price      int32
	Status     OrderStatus
	Items      []*OrderItem
	CreateTime time.Time
	UpdateTime time.Time
}

type OrderItem struct {
	Id       int64
	ItemId   int64
	ItemName string
	Number   int32
	Price    int32
}

type SearchOrderList struct {
	UserId     int64
	MerchantId int64
	PageSize   int32
	PageNo     int32
}

type Pagination struct {
	Total    int64
	PageSize int32
	PageNo   int32
}

type OrderUsecase interface {
	ListOrders(ctx context.Context, search *SearchOrderList) ([]*Order, Pagination, error)
	GetOrder(ctx context.Context, id int64) (*Order, error)
	CreateOrder(ctx context.Context, do *Order) (*Order, error)
	UpdateOrder(ctx context.Context, do *Order, mask []string) (*Order, error)
	DeleteOrder(ctx context.Context, id int64) error
}

type OrderRepo interface {
	Tx(ctx context.Context) (OrderRepo, error)
	Rollback() error
	Commit() error
	ListOrders(ctx context.Context, search *SearchOrderList) ([]*Order, int64, error)
	GetOrder(ctx context.Context, id int64) (*Order, error)
	CreateOrder(ctx context.Context, do *Order) (*Order, error)
	UpdateOrder(ctx context.Context, do *Order, mask []string) (*Order, error)
	DeleteOrder(ctx context.Context, id int64) error
}
